<?php
/**
 * Created by PhpStorm.
 * User: Powerless
 * Date: 16/12/30
 * Time: 14:37
 */

class Lives
{

    const APPID = '1253124583'; //appid
    const BIZID = '5853'; //bizid您在腾讯云分配到的bizid
    const KEY = 'dbc01eada3f9d4eeb796ef6ee1bbfe8c';//推流防盗链Key
    const APIKEY = '6dc130c3f562646591398c51bff3399c';//API鉴权Key
    const PAGE_NO = 1; //page_no
    const PAGE_SIZE = 20; //page_size
    const BID = 100; //count
    const LIST_STATUS = 1;//0表示断流，1表示开启，3表示关闭
    const SET_STATUS = 0;//0:关闭； 1:开启
    //文档地址
    //https://www.qcloud.com/document/product/267/6110
    const API_BASE_GET_URL_PREFIX = 'http://statcgi.video.qcloud.com/common_access?';//统计信息查询接口。GET方式请求
    const API_BASE_LIVE_URL_PREFIX = 'http://fcgi.video.qcloud.com/common_access?';//

    const GET_LIVESTAT = 'Get_LiveStat'; //统计信息查询 - 查询推流和播放相关信息
    const GET_LIVEPUSHSTAT = 'Get_LivePushStat'; //统计信息查询 - 查询推流相关信息
    const GET_LIVEPLAYSTAT = 'Get_LivePlayStat'; //统计信息查询 - 查询播放相关信息
    const GET_LIVEPUSHSTATHISTORY = 'Get_LivePushStatHistory'; //获取推流历史信息
    const GET_LIVEPLAYSTATHISTORY = 'Get_LivePlayStatHistory'; //获取播放统计历史信息

    const LIVE_CHANNEL_GETSTATUS = 'Live_Channel_GetStatus'; //仅查询某条流的状态信息（旧版本接口）
    const LIVE_CHANNEL_SETSTATUS = 'Live_Channel_SetStatus'; //对某条流实行禁播操作，主要用于鉴黄场景
    const LIVE_TAPE_GETFILELIST = 'Live_Tape_GetFilelist'; //查询某条流在直播过程中的录制文件列表
    const LIVE_QUEUE_GET = 'Live_Queue_Get'; //查询某条流在直播过程中的截图文件列表
    const LIVE_CHANNEL_GETCHANNELLIST = 'Live_Channel_GetChannelList'; //查询频道列表
    const LIVE_CHANNEL_GETLIVECHANNELLIST = 'Live_Channel_GetLiveChannelList'; //查询直播中频道列表

    const MIX_STREAMV2 = 'Mix_StreamV2'; //云端混流操作接口
    const CHANNEL_MANAGER = 'channel_manager'; //暂停并延迟恢复——可针对某路流禁止推流
    const LIVE_TAPE_START = 'Live_Tape_Start'; //创建录制任务——可实现定时录制任务或者实时视频录制
    const LIVE_TAPE_STOP = 'Live_Tape_Stop'; //结束录制任务

    /**
     * GET 请求
     * @param string $url
     * @return string content
     */
    private function httpGet($url){
        $oCurl = curl_init();
        if(stripos($url,"https://")!==FALSE){
            curl_setopt($oCurl, CURLOPT_SSL_VERIFYPEER, FALSE);
            curl_setopt($oCurl, CURLOPT_SSL_VERIFYHOST, FALSE);
            curl_setopt($oCurl, CURLOPT_SSLVERSION, 1); //CURL_SSLVERSION_TLSv1
        }
        curl_setopt($oCurl, CURLOPT_URL, $url);
        curl_setopt($oCurl, CURLOPT_RETURNTRANSFER, 1 );
        $sContent = curl_exec($oCurl);
        $aStatus = curl_getinfo($oCurl);
        curl_close($oCurl);
        if(intval($aStatus["http_code"])==200){
            return $sContent;
        }else{
            return false;
        }
    }

    /**
     * POST 请求
     * @param string $url
     * @param array $param
     * @param boolean $post_file 是否文件上传
     * @return string content
     */
    private function httpPost($url,$param,$post_file=false){
        $oCurl = curl_init();
        if(stripos($url,"https://")!==FALSE){
            curl_setopt($oCurl, CURLOPT_SSL_VERIFYPEER, FALSE);
            curl_setopt($oCurl, CURLOPT_SSL_VERIFYHOST, false);
            curl_setopt($oCurl, CURLOPT_SSLVERSION, 1); //CURL_SSLVERSION_TLSv1
        }
        if (is_string($param) || $post_file) {
            $strPOST = $param;
        } else {
            $aPOST = array();
            foreach($param as $key=>$val){
                $aPOST[] = $key."=".urlencode($val);
            }
            $strPOST =  join("&", $aPOST);
        }
        curl_setopt($oCurl, CURLOPT_URL, $url);
        curl_setopt($oCurl, CURLOPT_RETURNTRANSFER, 1 );
        curl_setopt($oCurl, CURLOPT_POST,true);
        curl_setopt($oCurl, CURLOPT_POSTFIELDS,$strPOST);
        $sContent = curl_exec($oCurl);
        $aStatus = curl_getinfo($oCurl);
        curl_close($oCurl);
        if(intval($aStatus["http_code"])==200){
            return $sContent;
        }else{
            return $aStatus;
        }
    }

    public function checkAuth ()
    {
        if(self::APPID && self::APIKEY) return true;
    }

    /**
     * 获取推流地址
     * 如果不传key和过期时间，将返回不含防盗链的url
     * @param int streamId 您用来区别不通推流地址的唯一id
     * @param time time 过期时间 sample 2016-11-12 12:00:00
     * @param int bizId 您在腾讯云分配到的bizId
     * @param tring key 安全密钥
     * @return String url
     */
    public function getPushUrl($streamId, $time,$bizId = self::BIZID,$key = self::KEY)
    {

        if($key && $time){
            $txTime = dechex($time);
            $liveCode = $bizId."_".$streamId; //直播码
            $txSecret = md5($key.$liveCode.$txTime);
            $ext_str = "?".http_build_query(array(
                    "bizid"=> $bizId,
                    "txSecret"=> $txSecret,
                    "txTime"=> $txTime
                ));
        }
        return "rtmp://".$bizId.".livepush.myqcloud.com/live/".$liveCode.(isset($ext_str) ? $ext_str : "");
    }

    /**
     * 获取播放地址
     * @param int $bizId 您在腾讯云分配到的bizid
     * @param String $streamId 您用来区别不通推流地址的唯一id
     * @return String url
     */
    public function getPlayUrl($streamId,$bizId = self::BIZID)
    {
        $livecode = $bizId.'_'.$streamId; //直播码
        $url = array(
            'rtmp://'.$bizId.'.liveplay.myqcloud.com/live/'.$livecode,
            'https://'.$bizId.'.liveplay.myqcloud.com/live/'.$livecode.'.flv',
            'https://'.$bizId.'.liveplay.myqcloud.com/live/'.$livecode.'.m3u8'
        );
        return $url;
    }

    /**
     * 获取播放地址
     * @param int $bizId 您在腾讯云分配到的bizid
     * @param String $streamId 您用来区别不通推流地址的唯一id
     * @return String url
     */
    public function rtmpLivePlay($streamId,$time,$bizId = self::BIZID,$key = self::KEY)
    {
        $txTime = dechex($time);
        $liveCode = $bizId."_".$streamId; //直播码
        $txSecret = md5($key.$liveCode.$txTime);
        $url = 'rtmp://'.$bizId.'.liveplay.myqcloud.com/live/'.$liveCode.'?bizid='.$bizId.'&txSecret='.$txSecret.'&txTime='.$txTime;
        return $url;
    }

    /**
     * 查询频道列表
     * @param int $time 时间戳
     * @param int $channel 房间号
     * @param int $status 状态
     * @param int $no 页码
     * @param int $size 每页数量
     * @return string $json 返回结果
     */
    public function channelStat($time,$channel, $no = self::PAGE_NO, $status = self::LIST_STATUS, $size = self::PAGE_SIZE)
    {
        if (!$this->checkAuth()) return false;
        $url = http_build_query(array(
            'appid' => self::APPID,
            'interface' => self::GET_LIVESTAT,
            't' => $time,
            'sign' => md5(self::APIKEY.$time),
            'Param.n.status' => $status,
            'Param.n.page_no' => $no,
            'Param.n.page_size' => $size,
            'Param.s.stream_id' => $channel
        ));
        $result = $this->httpGet(self::API_BASE_GET_URL_PREFIX . $url);
        if ($result) {
            $json = json_decode($result, true);
            if ($json['ret']) {
                return $json['message'];
            }
            return $json['output'];
        }
        return false;
    }

    /**
     * 查询直播状态
     * @param int $time 时间戳
     * @param int $channelId 直播码
     * @return string $json 返回结果
     */
    public function channelGetStatus($time, $channelId)
    {
        if (!$this->checkAuth()) return false;
        $url = http_build_query(array(
            'appid' => self::APPID,
            'interface' => self::LIVE_CHANNEL_GETSTATUS,
            't' => $time,
            'sign' => md5(self::APIKEY.$time),
            'Param.s.channel_id' => self::BIZID .'_'. $channelId,
        ));
        $result = $this->httpGet(self::API_BASE_LIVE_URL_PREFIX . $url);
        if ($result) {
            $json = json_decode($result, true);
            if ($json['ret']) {
                return $json['message'];
            }
            return $json['output'][0];
        }
        return false;
    }

    /**
     * 开启关闭推流
     * @param int $time 时间戳
     * @param int $channelId 直播码
     * @param int $status 开关状态
     * @return string $json 返回结果
     */
    public function channelSetStatus($time, $channelId,$status = self::SET_STATUS)
    {
        if (!$this->checkAuth()) return false;
        $url = http_build_query(array(
            'appid' => self::APPID,
            'interface' => self::LIVE_CHANNEL_SETSTATUS,
            't' => $time,
            'sign' => md5(self::APIKEY.$time),
            'Param.s.channel_id' => self::BIZID .'_'. $channelId,
            'Param.n.status' => $status,
        ));
        $result = $this->httpGet(self::API_BASE_LIVE_URL_PREFIX . $url);
        if ($result) {
            $json = json_decode($result, true);
            if ($json['ret']) {
                return $json['message'];
            }
            return $json['output'];
        }
        return false;
    }

    /**
     * 查询录制文件
     * @param int $time 时间戳
     * @param int $channelId 直播码
     * @param int $no 页码
     * @param int $size 每页数量
     * @return string $json 返回结果
     */
    public function channelGetFilelist($time,$channelId, $no = self::PAGE_NO, $size = self::PAGE_SIZE)
    {
        if (!$this->checkAuth()) return false;
        $url = http_build_query(array(
            'appid' => self::APPID,
            'interface' => self::LIVE_TAPE_GETFILELIST,
            't' => $time,
            'sign' => md5(self::APIKEY.$time),
            'Param.s.channel_id' => self::BIZID .'_'. $channelId,
            'Param.n.page_no' => $no,
            'Param.n.page_size' => $size
        ));
        $result = $this->httpGet(self::API_BASE_LIVE_URL_PREFIX . $url);
        if ($result) {
            $json = json_decode($result, true);
            if ($json['ret']) {
                return $json['message'];
            }
            return $json['output'];
        }
        return false;
    }

    /**
     * 查询截图文件
     * @param int $time 时间戳
     * @param int $bid 消息队列id
     * @param int $size 一次获取的消息数量
     * @return string $json 返回结果
     */
    public function channelQueueGet($time, $bid = self::BID, $size = self::PAGE_SIZE)
    {
        if (!$this->checkAuth()) return false;
        $url = http_build_query(array(
            'appid' => self::APPID,
            'interface' => self::LIVE_QUEUE_GET,
            't' => $time,
            'sign' => md5(self::APIKEY.$time),
            'Param.n.bid' => $bid,
            'Param.n.count' => $size
        ));
        $result = $this->httpGet(self::API_BASE_LIVE_URL_PREFIX . $url);
        if ($result) {
            $json = json_decode($result, true);
            if ($json['ret']) {
                return $json['message'];
            }
            return $json['output'];
        }
        return false;
    }

    /**
     * 查询频道列表
     * @param int $time 时间戳
     * @param int $status 状态
     * @param int $no 页码
     * @param int $size 每页数量
     * @return string $json 返回结果
     */
    public function channelList($time, $no = self::PAGE_NO, $status = self::LIST_STATUS, $size = self::PAGE_SIZE)
    {
        if (!$this->checkAuth()) return false;
        $url = http_build_query(array(
            'appid' => self::APPID,
            'interface' => self::LIVE_CHANNEL_GETCHANNELLIST,
            't' => $time,
            'sign' => md5(self::APIKEY.$time),
            'Param.n.status' => $status,
            'Param.n.page_no' => $no,
            'Param.n.page_size' => $size
        ));
        $result = $this->httpGet(self::API_BASE_LIVE_URL_PREFIX . $url);
        if ($result) {
            $json = json_decode($result, true);
            if ($json['ret']) {
                return $json['message'];
            }
            return $json['output']['channel_list'];
        }
        return false;
    }

    /**
     * 查询直播中频道列表
     * @param int $time 时间戳
     * @param int $status 状态
     * @param int $no 页码
     * @param int $size 每页数量
     * @return string $json 返回结果
     */
    public function channeLivelList($time)
    {
        if (!$this->checkAuth()) return false;
        $url = http_build_query(array(
            'appid' => self::APPID,
            'interface' => self::LIVE_CHANNEL_GETLIVECHANNELLIST,
            't' => $time,
            'sign' => md5(self::APIKEY.$time)
        ));
        $result = $this->httpGet(self::API_BASE_LIVE_URL_PREFIX . $url);
        if ($result) {
            $json = json_decode($result, true);
            if ($json['ret']) {
                return $json['message'];
            }
            return $json['output']['channel_list'];
        }
        return false;
    }

    /**
     * 云端混流
     * @param int $udid 用户ID
     * @return string $json 返回结果
     */
    public function stream($udids=[],$type=1)
    {
        if(!is_array($udids)){
            return '用户ID需要是数组';
        }
        if (!$this->checkAuth()) return false;
        $time = strtotime(date('Y-m-d H:i'))+300;
        $url = http_build_query(array(
            'appid' => self::APPID,
            'interface' => self::MIX_STREAMV2,
            't' => $time,
            'sign' => md5(self::APIKEY.$time),
        ));
        $color = '0x000000';
        $udid1 =  self::BIZID .'_'. $udids[0];
        if($type == 1){//田字格模式
            switch (count($udids)){
                case 1:
                    $para = [
                        'appid'=>self::APPID,
                        'interface'=>'mix_streamv2.start_mix_stream_advanced',
                        'mix_stream_session_id'=>$udid1,
                        'output_stream_id'=>$udid1,
                        'output_stream_type'=>0,
                        'input_stream_list'=>[
                            [
                                'input_stream_id'=>'',
                                'layout_params'=>[
                                    'image_layer' => 1,
                                    'input_type'=>3,
                                    'color'=>$color,
                                    'image_width'=>750,
                                    'image_height'=>1333
                                ]
                            ],
                            [
                                'input_stream_id'=>$udid1,
                                'layout_params'=>[
                                    'image_layer' => 2,
                                    'image_width'=>750,
                                    'image_height'=>1333
                                ]
                            ]
                        ]
                    ];
                    break;
                case 2:
                    $udid2 =  self::BIZID .'_'. $udids[1];
                    $para = [
                        'appid'=>self::APPID,
                        'interface'=>'mix_streamv2.start_mix_stream_advanced',
                        'mix_stream_session_id'=>$udid1,
                        'output_stream_id'=>$udid1,
                        'output_stream_type'=>0,
                        'mix_stream_template_id'=>390,
                        'input_stream_list'=>[
                            [
                                'input_stream_id'=>'',
                                'layout_params'=>[
                                    'image_layer' => 1,
                                    'input_type'=>3,
                                    'color'=>$color,
                                    'image_width'=>750,
                                    'image_height'=>1333
                                ]
                            ],
                            [
                                'input_stream_id'=>$udid1,
                                'layout_params'=>[
                                    'image_layer' => 2,
                                ]
                            ],
                            [
                                'input_stream_id'=>$udid2,
                                'layout_params'=>[
                                    'image_layer' => 3,
                                ]

                            ]
                        ]
                    ];
                    break;
                case 3:
                    $udid2 =  self::BIZID .'_'. $udids[1];
                    $udid3 =  self::BIZID .'_'. $udids[2];
                    $para = [
                        'appid'=>self::APPID,
                        'interface'=>'mix_streamv2.start_mix_stream_advanced',
                        'mix_stream_session_id'=>$udid1,
                        'output_stream_id'=>$udid1,
                        'input_stream_list'=>[
                            [
                                'input_stream_id'=>'',
                                'layout_params'=>[
                                    'image_layer' => 1,
                                    'input_type'=>3,
                                    'color'=>$color,
                                    'image_width'=>750,
                                    'image_height'=>1333
                                ]
                            ],
                            [
                                'input_stream_id'=>$udid1,
                                'layout_params'=>[
                                    'image_layer' => 2,
                                    'image_width'=>375,
                                    'image_height'=>667,
                                    'location_x'=>0,
                                    'location_y'=>0
                                ]
                            ],
                            [
                                'input_stream_id'=>$udid2,
                                'layout_params'=>[
                                    'image_layer' => 3,
                                    'image_width'=>375,
                                    'image_height'=>667,
                                    'location_x'=>375,
                                    'location_y'=>0
                                ]

                            ],
                            [
                                'input_stream_id'=>$udid3,
                                'layout_params'=>[
                                    'image_layer' => 4,
                                    'image_width'=>375,
                                    'image_height'=>667,
                                    'location_x'=>0,
                                    'location_y'=>375
                                ]
                            ]
                        ]
                    ];
                    break;
                case 4:
                    $udid2 =  self::BIZID .'_'. $udids[1];
                    $udid3 =  self::BIZID .'_'. $udids[2];
                    $udid4 =  self::BIZID .'_'. $udids[3];
                    $para = [
                        'appid'=>self::APPID,
                        'interface'=>'mix_streamv2.start_mix_stream_advanced',
                        'mix_stream_session_id'=>$udid1,
                        'output_stream_id'=>$udid1,
                        'output_stream_type'=>0,
                        'mix_stream_template_id'=>590,
                        'input_stream_list'=>[
                            [
                                'input_stream_id'=>'',
                                'layout_params'=>[
                                    'image_layer' => 1,
                                    'input_type'=>3,
                                    'color'=>$color,
                                    'image_width'=>750,
                                    'image_height'=>1333
                                ]
                            ],
                            [
                                'input_stream_id'=>$udid1,
                                'layout_params'=>[
                                    'image_layer' => 2,
                                    'image_width'=>375,
                                    'image_height'=>667,
                                ]
                            ],
                            [
                                'input_stream_id'=>$udid2,
                                'layout_params'=>[
                                    'image_layer' => 3,
                                    'image_width'=>375,
                                    'image_height'=>667,
                                ]

                            ],
                            [
                                'input_stream_id'=>$udid3,
                                'layout_params'=>[
                                    'image_layer' => 4,
                                    'image_width'=>375,
                                    'image_height'=>667,
                                ]
                            ],
                            [
                                'input_stream_id'=>$udid4,
                                'layout_params'=>[
                                    'image_layer' => 5,
                                    'image_width'=>375,
                                    'image_height'=>667,
                                ]
                            ]
                        ]
                    ];
                    break;
                default:
                    $para = [];
            }
        }elseif($type == 2){//主播最大模式
            switch (count($udids)){
                case 1:
                    $para = [
                        'appid'=>self::APPID,
                        'interface'=>'mix_streamv2.start_mix_stream_advanced',
                        'mix_stream_session_id'=>$udid1,
                        'output_stream_id'=>$udid1,
                        'input_stream_list'=>[
                            [
                                'input_stream_id'=>'',
                                'layout_params'=>[
                                    'image_layer' => 1,
                                    'input_type'=>3,
                                    'color'=>$color,
                                    'image_width'=>450,
                                    'image_height'=>800
                                ]
                            ],
                            [
                                'input_stream_id'=>$udid1,
                                'layout_params'=>[
                                    'image_layer' => 2,
                                    'image_width'=>450,
                                    'image_height'=>800,
                                    'location_x'=>0,
                                    'location_y'=>0
                                ]
                            ]
                        ]
                    ];
                    break;
                case 2:
                    $udid2 =  self::BIZID .'_'. $udids[1];
                    $para = [
                        'appid'=>self::APPID,
                        'interface'=>'mix_streamv2.start_mix_stream_advanced',
                        'mix_stream_session_id'=>$udid1,
                        'output_stream_id'=>$udid1,
                        'input_stream_list'=>[
                            [
                                'input_stream_id'=>'',
                                'layout_params'=>[
                                    'image_layer' => 1,
                                    'input_type'=>3,
                                    'color'=>$color,
                                    'image_width'=>450,
                                    'image_height'=>800
                                ]
                            ],
                            [
                                'input_stream_id'=>$udid1,
                                'layout_params'=>[
                                    'image_layer' => 2,
                                    'image_width'=>450,
                                    'image_height'=>800,
                                    'location_x'=>0,
                                    'location_y'=>0
                                ]
                            ],
                            [
                                'input_stream_id'=>$udid2,
                                'layout_params'=>[
                                    'image_layer' => 3,
                                    'image_width'=>90,
                                    'image_height'=>160,
                                    'location_x'=>30,
                                    'location_y'=>610
                                ]

                            ]
                        ]
                    ];
                    break;
                case 3:
                    $udid2 =  self::BIZID .'_'. $udids[1];
                    $udid3 =  self::BIZID .'_'. $udids[2];
                    $para = [
                        'appid'=>self::APPID,
                        'interface'=>'mix_streamv2.start_mix_stream_advanced',
                        'mix_stream_session_id'=>$udid1,
                        'output_stream_id'=>$udid1,
                        'input_stream_list'=>[
                            [
                                'input_stream_id'=>'',
                                'layout_params'=>[
                                    'image_layer' => 1,
                                    'input_type'=>3,
                                    'color'=>$color,
                                    'image_width'=>450,
                                    'image_height'=>800
                                ]
                            ],
                            [
                                'input_stream_id'=>$udid1,
                                'layout_params'=>[
                                    'image_layer' => 2,
                                    'image_width'=>450,
                                    'image_height'=>800,
                                    'location_x'=>0,
                                    'location_y'=>0
                                ]
                            ],
                            [
                                'input_stream_id'=>$udid2,
                                'layout_params'=>[
                                    'image_layer' => 3,
                                    'image_width'=>90,
                                    'image_height'=>160,
                                    'location_x'=>30,
                                    'location_y'=>610
                                ]

                            ],
                            [
                                'input_stream_id'=>$udid3,
                                'layout_params'=>[
                                    'image_layer' => 4,
                                    'image_width'=>90,
                                    'image_height'=>160,
                                    'location_x'=>180,
                                    'location_y'=>610
                                ]
                            ]
                        ]
                    ];
                    break;
                case 4:
                    $udid2 =  self::BIZID .'_'. $udids[1];
                    $udid3 =  self::BIZID .'_'. $udids[2];
                    $udid4 =  self::BIZID .'_'. $udids[3];
                    $para = [
                        'appid'=>self::APPID,
                        'interface'=>'mix_streamv2.start_mix_stream_advanced',
                        'mix_stream_session_id'=>$udid1,
                        'output_stream_id'=>$udid1,
                        'input_stream_list'=>[
                            [
                                'input_stream_id'=>'',
                                'layout_params'=>[
                                    'image_layer' => 1,
                                    'input_type'=>3,
                                    'color'=>$color,
                                    'image_width'=>450,
                                    'image_height'=>800
                                ]
                            ],
                            [
                                'input_stream_id'=>$udid1,
                                'layout_params'=>[
                                    'image_layer' => 2,
                                    'image_width'=>450,
                                    'image_height'=>800,
                                    'location_x'=>0,
                                    'location_y'=>0
                                ]
                            ],
                            [
                                'input_stream_id'=>$udid2,
                                'layout_params'=>[
                                    'image_layer' => 3,
                                    'image_width'=>90,
                                    'image_height'=>160,
                                    'location_x'=>30,
                                    'location_y'=>610
                                ]

                            ],
                            [
                                'input_stream_id'=>$udid3,
                                'layout_params'=>[
                                    'image_layer' => 4,
                                    'image_width'=>90,
                                    'image_height'=>160,
                                    'location_x'=>180,
                                    'location_y'=>610
                                ]
                            ],
                            [
                                'input_stream_id'=>$udid4,
                                'layout_params'=>[
                                    'image_layer' => 5,
                                    'image_width'=>90,
                                    'image_height'=>160,
                                    'location_x'=>330,
                                    'location_y'=>610
                                ]
                            ]
                        ]
                    ];
                    break;
                default:
                    $streamList = [];
            }
        }elseif($type == 3){//所选最大模式
            switch (count($udids)){
                case 1:
                    $para = [
                        'appid'=>self::APPID,
                        'interface'=>'mix_streamv2.start_mix_stream_advanced',
                        'mix_stream_session_id'=>$udid1,
                        'output_stream_id'=>$udid1,
                        'input_stream_list'=>[
                            [
                                'input_stream_id'=>'',
                                'layout_params'=>[
                                    'image_layer' => 1,
                                    'input_type'=>3,
                                    'color'=>$color,
                                    'image_width'=>450,
                                    'image_height'=>800
                                ]
                            ],
                            [
                                'input_stream_id'=>$udid1,
                                'layout_params'=>[
                                    'image_layer' => 2,
                                    'image_width'=>450,
                                    'image_height'=>800,
                                    'location_x'=>0,
                                    'location_y'=>0
                                ]
                            ]
                        ]
                    ];
                    break;
                case 2:
                    $udid2 =  self::BIZID .'_'. $udids[1];
                    $para = [
                        'appid'=>self::APPID,
                        'interface'=>'mix_streamv2.start_mix_stream_advanced',
                        'mix_stream_session_id'=>$udid1,
                        'output_stream_id'=>$udid1,
                        'input_stream_list'=>[
                            [
                                'input_stream_id'=>'',
                                'layout_params'=>[
                                    'image_layer' => 1,
                                    'input_type'=>3,
                                    'color'=>$color,
                                    'image_width'=>450,
                                    'image_height'=>800
                                ]
                            ],
                            [
                                'input_stream_id'=>$udid2,
                                'layout_params'=>[
                                    'image_layer' => 2,
                                    'image_width'=>450,
                                    'image_height'=>800,
                                    'location_x'=>0,
                                    'location_y'=>0
                                ]
                            ],
                            [
                                'input_stream_id'=>$udid1,
                                'layout_params'=>[
                                    'image_layer' => 3,
                                    'image_width'=>90,
                                    'image_height'=>160,
                                    'location_x'=>30,
                                    'location_y'=>610
                                ]

                            ]
                        ]
                    ];
                    break;
                case 3:
                    $udid2 =  self::BIZID .'_'. $udids[1];
                    $udid3 =  self::BIZID .'_'. $udids[2];
                    $para = [
                        'appid'=>self::APPID,
                        'interface'=>'mix_streamv2.start_mix_stream_advanced',
                        'mix_stream_session_id'=>$udid1,
                        'output_stream_id'=>$udid1,
                        'input_stream_list'=>[
                            [
                                'input_stream_id'=>'',
                                'layout_params'=>[
                                    'image_layer' => 1,
                                    'input_type'=>3,
                                    'color'=>$color,
                                    'image_width'=>450,
                                    'image_height'=>800
                                ]
                            ],
                            [
                                'input_stream_id'=>$udid2,
                                'layout_params'=>[
                                    'image_layer' => 2,
                                    'image_width'=>450,
                                    'image_height'=>800,
                                    'location_x'=>0,
                                    'location_y'=>0
                                ]
                            ],
                            [
                                'input_stream_id'=>$udid1,
                                'layout_params'=>[
                                    'image_layer' => 3,
                                    'image_width'=>90,
                                    'image_height'=>160,
                                    'location_x'=>30,
                                    'location_y'=>610
                                ]

                            ],
                            [
                                'input_stream_id'=>$udid3,
                                'layout_params'=>[
                                    'image_layer' => 4,
                                    'image_width'=>90,
                                    'image_height'=>160,
                                    'location_x'=>180,
                                    'location_y'=>610
                                ]
                            ]
                        ]
                    ];
                    break;
                case 4:
                    $udid2 =  self::BIZID .'_'. $udids[1];
                    $udid3 =  self::BIZID .'_'. $udids[2];
                    $udid4 =  self::BIZID .'_'. $udids[3];
                    $para = [
                        'appid'=>self::APPID,
                        'interface'=>'mix_streamv2.start_mix_stream_advanced',
                        'mix_stream_session_id'=>$udid1,
                        'output_stream_id'=>$udid1,
                        'input_stream_list'=>[
                            [
                                'input_stream_id'=>'',
                                'layout_params'=>[
                                    'image_layer' => 1,
                                    'input_type'=>3,
                                    'color'=>$color,
                                    'image_width'=>450,
                                    'image_height'=>800
                                ]
                            ],
                            [
                                'input_stream_id'=>$udid2,
                                'layout_params'=>[
                                    'image_layer' => 2,
                                    'image_width'=>450,
                                    'image_height'=>800,
                                    'location_x'=>0,
                                    'location_y'=>0
                                ]
                            ],
                            [
                                'input_stream_id'=>$udid1,
                                'layout_params'=>[
                                    'image_layer' => 3,
                                    'image_width'=>90,
                                    'image_height'=>160,
                                    'location_x'=>30,
                                    'location_y'=>610
                                ]

                            ],
                            [
                                'input_stream_id'=>$udid3,
                                'layout_params'=>[
                                    'image_layer' => 4,
                                    'image_width'=>90,
                                    'image_height'=>160,
                                    'location_x'=>180,
                                    'location_y'=>610
                                ]
                            ],
                            [
                                'input_stream_id'=>$udid4,
                                'layout_params'=>[
                                    'image_layer' => 5,
                                    'image_width'=>90,
                                    'image_height'=>160,
                                    'location_x'=>330,
                                    'location_y'=>610
                                ]
                            ]
                        ]
                    ];
                    break;
                default:
                    $para = [];
            }
        }else{
            $para = [
                'appid'=>self::APPID,
                'interface'=>'mix_streamv2.start_mix_stream_advanced',
                'mix_stream_session_id'=>$udid1,
                'output_stream_id'=>$udid1,
                'input_stream_list'=>[
                    [
                        'input_stream_id'=>'',
                        'layout_params'=>[
                            'image_layer' => 1,
                            'input_type'=>3,
                            'color'=>$color,
                        ]
                    ],
                    [
                        'input_stream_id'=>$udid1,
                        'layout_params'=>[
                            'image_layer' => 2,
                        ]
                    ]
                ]
            ];
        }

        $body = [
            'timestamp'=>$time,
            'eventId'=>$time,
            'interface'=>[
                'interfaceName'=>"Mix_StreamV2",
                'para'=>$para,
            ]
        ];
        Log::write($para,'para:'.$type);
        $result = $this->httpPost(self::API_BASE_LIVE_URL_PREFIX . $url,json_encode($body));
        if ($result) {
            $json = json_decode($result, true);
            if ($json['code']) {
                return $json['message'];
            }
            return $json['message'];
        }
        return '混流请求错误';
    }

}